package jvm;

import tech.medivh.classpy.classfile.MethodInfo;
import tech.medivh.classpy.classfile.bytecode.Instruction;
import tech.medivh.classpy.classfile.constant.ConstantPool;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;

public class StackFrame {
    // 方法信息
    private MethodInfo methodInfo;
    // 局部变量表
    private Object[] LocalVariable;
    // 操作数栈
    private Deque<Object> operandStack;
    // 指令集
    private List<Instruction> codes;
    // 当前执行的指令
    int currentIndex;

    /**
     * 构造函数
     * @param methodInfo 方法信息
     * @param constantPool 常量池
     * @param args 方法参数
     */
    public StackFrame(MethodInfo methodInfo, ConstantPool constantPool,Object... args){
        this.methodInfo = methodInfo;
        this.LocalVariable = new Object[methodInfo.getMaxLocals()];
        this.operandStack = new ArrayDeque<>();
        this.codes = methodInfo.getCodes();
        System.arraycopy(args,0,LocalVariable,0,args.length);
    }
}
